<?php
	include "common.php";
	error_reporting(0);
	session_start();
	if($_SESSION['logInCheck']!=1){
		header('Location: index.php?loginInfo=false');
	}
	$userLink = $_SESSION['userLink'];
	if($userLink!="hrpage.php"){
		echo "Sorry, You have no right to visit this page!!";
		exit;
	}
	$eid = $_SESSION['id'];
	/*$userFname = $_SESSION['userFname'];
	$userLname = $_SESSION['userLname'];
	$role = $_SESSION['role'];
	
	$userSql = "SELECT * FROM user WHERE e_id = '$eid'";
	$userSqlQuery = mysql_query($userSql);
	$userSqlResult = mysql_fetch_assoc($userSqlQuery);*/
	$checkSubmit=$_POST['check'];
	/*$email = $userSqlResult['email'];
	$notification = $userSqlResult['notification'];
	$timezone_offset = 6; // for getting local time offset hrs
	$systemDate = gmdate('y-m-d', time()+$timezone_offset*60*60);
	$compToday = strtotime($systemDate);*/
	if($checkSubmit==1){		
		$collectNewHour = $_POST['hour'];
		$collectNewMinuite = $_POST['minuite'];
		$updateOfficeTime = "UPDATE user SET office_hour='$collectNewHour',office_minute='$collectNewMinuite' WHERE status=0";
		$updateOfficeTimeQuery=mysql_query($updateOfficeTime);
		$myFile = "officeTime.txt";
		$fh = fopen($myFile, 'w') or die("can't open file");
		$stringData = $collectNewHour.".".$collectNewMinuite."\n";
		fwrite($fh, $stringData);
		fclose($fh);
	}
	$sqlForOfficeTime = "SELECT * from user WHERE e_id='$eid'";
	$sqlForOfficeTimeQuery=mysql_query($sqlForOfficeTime);
	$time=mysql_fetch_array($sqlForOfficeTimeQuery);
	$prevHour=$time['office_hour'];
	$prevminuite=$time['office_minute'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="index.css" type="text/css" />
<link rel="icon" type="image/ico" href="images/favicon.ico"></link> 
<link rel="shortcut icon" href="images/favicon.ico"></link>
<link rel="stylesheet" type="text/css" href="jquery.alerts.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery-ui.js" type="text/javascript"></script>
<script src="jquery.ui.draggable" type="text/javascript"></script>
<script src="jquery.alerts.js" type="text/javascript"></script>
<script src="curvycorners.src.js" type="text/javascript"></script>
<script src="login.js" type="text/javascript"></script>
<title><?php echo "Welcome to ".$userFname." ".$userLname; ?></title>
</head>

<body>
<div class="main_div_other">
	<p><img src="images/creato_logo.jpg" /></p>
    <p id="creatobd">www.creatobd.com</p>
    <p id="date"><script>document.write(new_month+" "+new_date+", "+old_date.getFullYear()+" || "+new_day);</script></p>
    <div class="other_page_icons">
    	<div class="new_notification">
        	<img src="images/arrow_up.JPG" /><?php if ($notification >0){?><p>You have<?php echo " ".$notification." ";?>new notification</p><?php }?>
        </div><!--end of new_notification-->
    	<ul>
        	<a href="hrpage.php" class="active"><li><div id="home"></div><p>home</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_employee.php"><li><div id="employee"></div><p>employee</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_onduty.php"><li><div id="onduty"></div><p>on duty</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_attendance.php"><li><div id="attendance"></div><p>attendance</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_leave.php"><li><div id="leave"></div><p>leave</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_notification.php"><li><div id="notification"></div><p>notification</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="hr_black_box_message.php"><li><div id="blackbox"></div><p>black box</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="#"><li><div id="hrpolicy"></div><p>hr policy</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
            <a href="index.php"><li><div id="logout"></div><p>log out</p><p class="present_class"><img src="images/arrow_up.JPG" border="none"/></p></li></a>
        </ul>
    </div><!-- end of other_page_icons-->
    
</div><!-- end of main_div_other-->
<div class="othrpage_1">
	<p><a href="update_office_time.php">Update Office Time</a></p>
</div><!-- end of othrpage_1-->
<div class="page_content">
	<form method="post" action="update_office_time.php" class="update_user_add_table">	
        <table cellpadding="0" cellspacing="0" class="apply4leave_table" style="margin:0 auto;">
                <tr valign="top">
                		<?php
						if($checkSubmit==1){
						?>
                            <td  class="add_user_td1">The new office time</td>
                            <td><?php echo date('h:i A',strtotime($prevHour.":".$prevminuite)); ?></td>
                            <td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
                        <?php
						}
						else{
						?>
                    		<td  class="add_user_td1">The office Time is now</td>
                    		<td><?php  echo date('h:i A',strtotime($prevHour.":".$prevminuite)); ?></td>
                    		<td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>             
                        <?php
						}
						?>
                </tr>
                <tr>
                    <td class="add_user_td1">Select New Time</td>
                    <td></td>
                    <td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>             
                </tr>
                <tr>
                	<td class="add_user_td1">Select New Hour</td>
                    <td>
                    	<select name="hour">
                        	<option value="8">8 AM</option>
                            <option value="9">9 AM</option>
                            <option value="10">10 AM</option>
                            <option value="11">11 AM</option>
                            <option value="12">12 PM</option>
                            <option value="13">1 PM</option>
                        </select>
                    </td>
                    <td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
                </tr>
                <tr>
                	<td class="add_user_td1">Select New Minuite</td>
                    <td>
                    	<select name="minuite">
                        <?php
						for($i=0;$i<60;$i++){
						?>
                        	<option value="<?php echo $i; ?>"><?php echo $i; ?></option>
                        <?php
						}
						?>
                        </select>
                    </td>
                    <td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
                </tr>
                <tr>
					<td colspan='2'><p class="submit_button_add_user"><input type="submit" value="Submit"/></p></td>
					<td style="width:10px; background:#eff2f6; padding:0px !important;">&nbsp;</td>
				</tr>
        </table>
        <input type="hidden" value="1" name="check" />
    </form>
</div>

<div class="human_portal">
  		<p>creato human resourse portal</p>
</div><!-- end of human_portal-->


<script type="text/javascript">
	$(document).ready(function() {
	  notification_on(); 	
	  function notification_on()
	  {
	   	$('.new_notification').fadeIn(1);
	  }
	});
</script>

</body>
</html>